//
//  CentralCache.h
//  ConcurrentMemoryPool
//
//  Created by 张木林 on 5/6/25.
//

#pragma once

#include "Common.hpp"

// 单例模式
class CentralCache
{
public:
    static CentralCache* GetInstance()
    {
        return &_sInst;
    }

    // 获取一个非空的span
    Span* GetOneSpan(SpanList& list, size_t byte_size);

    // 从中心缓存获取一定数量的对象给thread cache
    size_t FetchRangeObj(void*& start, void*& end, size_t batchNum, size_t size);
    
    //将一定数量的对象释放到span跨度
    //void FetchRangeObj(void* start,size_t byte_size);
    void ReleaseListToSpans(void* start,size_t byte_size);

private:
    SpanList _spanLists[NFREELIST];

private:
    CentralCache()
    {}

    CentralCache(const CentralCache&) = delete;

    static CentralCache _sInst;
};
